using System;
using Audio;
using PrimeTween;
using UnityEngine;

namespace Bubbles
{
    public class BubbleAnimator : MonoBehaviour
    {
        [SerializeField] private SpriteRenderer bubbleBackground;
        [SerializeField] private AudioClip hitSound;
        
        
        public void OnLanded()
        {
            Tween.ScaleY(bubbleBackground.transform, 0.8f, 0.2f, Ease.OutExpo)
                .Group(Tween.ScaleX(bubbleBackground.transform, 1.1f, 0.2f, Ease.OutExpo))
                .Chain(Tween.ScaleY(bubbleBackground.transform, 1f, 0.2f))
                .Group(Tween.ScaleX(bubbleBackground.transform, 1f, 0.2f));
        }

        private void OnCollisionEnter2D(Collision2D other)
        {
            OnLanded();
            AudioPlayer.Instance.PlaySound(hitSound);
        }
    }
}
